package com.jenkins.test.proxy.doscan;

import org.springframework.cglib.proxy.InvocationHandler;
import org.springframework.cglib.proxy.Proxy;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @version V0.0.1
 * @ClassName: {@link InterfaceProxy}
 * @Description: InterfaceProxy
 * @author: Lanzhou
 * @date: 2022/1/22 22:38
 * @Copyright:2019 All rights reserved.
 * 注意：本内容仅限于本人开发与维护，禁止外泄以及用于其他的商业目
 */
public class InterfaceProxy<T> implements InvocationHandler {

    /**
     * dao的class
     */
    private Class<T> interfaceClass;

    public Object bind(Class<T> cls) {
        this.interfaceClass = cls;
        return Proxy.newProxyInstance(cls.getClassLoader(), new Class[]{interfaceClass}, this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("ObjectProxy execute:" + method.getName());
        String param = Arrays.toString(args);
        return "pepsi is param=" + param;
    }

    public Class<T> getInterfaceClass() {
        return interfaceClass;
    }

    public void setInterfaceClass(Class<T> interfaceClass) {
        this.interfaceClass = interfaceClass;
    }
}
